﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.Serialization;

namespace WeatherServiceLibrary.Code
{
    [DataContract]
    public class Station : BaseWeather
    {


        private string _wmocode;

        [DataMember]
        public string Wmocode
        {
            get { return _wmocode; }
            set { }
        }

        private string _name;

        [DataMember]
        public string Name
        {
            get { return _name; }
            set { }
        }
        private List<StationObservation> statObs;

        [DataMember]
        public List<StationObservation> StationObservations
        {
            get { return statObs; }
            set { }
        }


        public Station(DBA.WeatherDB.Station station)
        {
            Id = station.StationID;
            this._wmocode = station.Wmocode;
            this._name = station.name;
            this.statObs = getObservationsList(station);

        }

        private List<StationObservation> getObservationsList(DBA.WeatherDB.Station station)
        {
            using (DBA.WeatherDB.WeatherBaseDataContext db = new DBA.WeatherDB.WeatherBaseDataContext())
            {

                var query = from x in db.StationObservations.Where(x => station.StationID == x.StationID)
                            select new StationObservation(x);
                return query.ToList();

            }
        }
    }
}
